package com.distribute.framework.core.web.servlet.upload;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UpLoadSession {	
	static List<UpLoadProgress> prolist=new ArrayList();
	static Map<String,UpLoadProgress> promap=new HashMap();
	
	public static UpLoadProgress get(String task){
		return promap.get(task);
	}
	
	public static synchronized void put(String task,UpLoadProgress progress){
		if(progress==null){
			UpLoadProgress p = promap.get(task);
			if(p!=null){
				prolist.remove(p);
				promap.remove(task);
			}
			return;
		}
		progress.setTask(task);
		promap.put(task, progress);
		prolist.add(progress);		
		UpLoadProgress historyProgress=prolist.get(0);
		Date now=new Date();
		long howlong = now.getTime()-historyProgress.getStart().getTime();
		if(howlong>(1000*60*60*1)){//如果超过一小时，则移除该任务
			promap.remove(historyProgress.getTask());
			prolist.remove(0);			
		}
	}
}